package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;

import org.cbg.until.TraslationDemoScrollBarUI;
import org.come.Frame.Change_titleJframe;
import org.come.model.Title;
import org.come.until.SrcollPanelUI;
import org.come.until.UserMessUntil;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.RoleOperationPanelBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;



/**
 * 称谓面板
 *
 * @author Administrator
 *
 */
public class Change_titleJpanel extends JPanel {

	private JLabel labnamech;// 放置称谓的控件

	// 放置称谓列表的滚动条
	private JScrollPane jScrollPane;

	// 放置称谓的列表框
	private JList<String> listname;
	// 放置称谓的列表对象
	private DefaultListModel<String> modelname;

	private RoleOperationPanelBtn btnsure,// 确认按钮
			btnhide;// 隐藏按钮
	private Change_titleJframe change_titleJframe;

	private JTextArea textArea; // 称谓介绍


	public Change_titleJpanel(Change_titleJframe change_titleJframe) throws Exception {
		if (MyIsif.getStyle().equals("水墨UI")){
			// 键盘监听
			this.change_titleJframe = change_titleJframe;
			this.setPreferredSize(new Dimension(288, 398));
			this.setLayout(null);
			this.setBackground(UIUtils.Color_BACK);

			// 关闭按钮事件
			FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 10);
			offBtn.setBounds(288 - 37, 10, 25, 25);
			this.add(offBtn);

			modelname = new DefaultListModel<String>();

			// 称谓列表
			listname = new JList<String>() {
				{
					setOpaque(false);
				} // instance initializer
			};

			listname.setSelectionBackground(new Color(33, 42, 52));
			listname.setSelectionForeground(Color.CYAN);
			listname.setForeground(Color.CYAN);
			listname.setFont(new Font("微软雅黑", 1, 14));
			listname.setOpaque(false);
			listname.addMouseListener(new MouseAdapter() {
				@Override
				public void mousePressed(MouseEvent e) {
					String selectedValue = listname.getSelectedValue();
					if (selectedValue != null) {
						textArea.setText("");
						Title title = UserMessUntil.getTitle(selectedValue);
						if(title == null){
							return;
						}
						if(title.getText()!=null){
							textArea.append(title.getText()+"\r\n");
						}
						if(title.getValue()!=null){
							textArea.append(title.getValue().replace("\\|", ","));
						}
					}
				}
			});
			listname.setBackground(new Color(0, 0, 0, 0));
			listname.setModel(modelname);

			// 称谓列表滚动条
			jScrollPane = new JScrollPane(listname);
			jScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			jScrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
			jScrollPane.getViewport().setOpaque(false);
			jScrollPane.setOpaque(false);
			jScrollPane.setBounds(58, 78, 204, 130);
			jScrollPane.setBorder(BorderFactory.createEmptyBorder());
			jScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
			this.add(jScrollPane);

			// 放置称谓
			labnamech = new JLabel();
			labnamech.setBounds(130, 46-13, 111 + 17, 16);
			labnamech.setForeground(Color.CYAN);
			labnamech.setFont(new Font("微软雅黑", 0, 12));
			this.add(labnamech);

			// 更改按钮
			btnsure = new RoleOperationPanelBtn("skin/8100226/newbutton/B22.png", 1, "更改称谓", this,null);
			btnsure.setBounds(45, 248 + 86 + 22,99, 24);
			this.add(btnsure);// 将按钮加到面板中去

			// 隐藏按钮
			btnhide = new RoleOperationPanelBtn("skin/8100226/newbutton/B22.png", 1, "隐藏称谓", this,null);
			btnhide.setBounds(164, 248 + 86 + 22,99, 24);
			this.add(btnhide);// 将按钮加到面板中去

			textArea = new JTextArea();
			textArea.setBounds(56, 210, 202, 100);
			textArea.setEditable(false);
			textArea.setLineWrap(true);
			textArea.setOpaque(false);
			textArea.setForeground(Color.white);
			this.add(textArea);
		}else {
			// 键盘监听
			this.change_titleJframe = change_titleJframe;
			this.setPreferredSize(new Dimension(288, 398));
			this.setLayout(null);
			this.setBackground(UIUtils.Color_BACK);

			// 关闭按钮事件
			FormsOnOffBtn offBtn = new FormsOnOffBtn("img/xy2uiimg/8_jpg.button.btn_close.jpg", 1, 10);
			offBtn.setBounds(288 - 37, 10, 25, 25);
			this.add(offBtn);

			modelname = new DefaultListModel<String>();

			// 称谓列表
			listname = new JList<String>() {
				{
					setOpaque(false);
				} // instance initializer
			};

			listname.setSelectionBackground(new Color(33, 42, 52));
			listname.setSelectionForeground(Color.CYAN);
			listname.setForeground(Color.CYAN);
			listname.setFont(new Font("微软雅黑", 1, 14));
			listname.setOpaque(false);
			listname.addMouseListener(new MouseAdapter() {
				@Override
				public void mousePressed(MouseEvent e) {
					String selectedValue = listname.getSelectedValue();
					if (selectedValue != null) {
						textArea.setText("");
						Title title = UserMessUntil.getTitle(selectedValue);
						if(title == null){
							return;
						}
						if(title.getText()!=null){
							textArea.append(title.getText()+"\r\n");
						}
						if(title.getValue()!=null){
							textArea.append(title.getValue().replace("\\|", ","));
						}
					}
				}
			});
			listname.setBackground(new Color(0, 0, 0, 0));
			listname.setModel(modelname);

			// 称谓列表滚动条
			jScrollPane = new JScrollPane(listname);
			jScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			jScrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
			jScrollPane.getViewport().setOpaque(false);
			jScrollPane.setOpaque(false);
			jScrollPane.setBounds(61, 76, 204, 130);
			jScrollPane.setBorder(BorderFactory.createEmptyBorder());
			jScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
			this.add(jScrollPane);

			// 放置称谓
			labnamech = new JLabel();
			labnamech.setBounds(130, 46-13, 111 + 17, 16);
			labnamech.setForeground(Color.CYAN);
			labnamech.setFont(new Font("微软雅黑", 0, 12));
			this.add(labnamech);

			// 更改按钮
			btnsure = new RoleOperationPanelBtn("inkImg/hongmu/1_png.button.btn_xy.png", 1, "更改称谓", this,null);
			btnsure.setBounds(45, 248 + 86 + 22,99, 24);
			btnsure.setForeground(Color.YELLOW);
			this.add(btnsure);// 将按钮加到面板中去

			// 隐藏按钮
			btnhide = new RoleOperationPanelBtn("inkImg/hongmu/1_png.button.btn_xy.png", 1, "隐藏称谓", this,null);
			btnhide.setBounds(164, 248 + 86 + 22,99, 24);
			btnhide.setForeground(Color.YELLOW);
			this.add(btnhide);// 将按钮加到面板中去

			textArea = new JTextArea();
			textArea.setBounds(56, 210, 202, 100);
			textArea.setEditable(false);
			textArea.setLineWrap(true);
			textArea.setOpaque(false);
			textArea.setForeground(Color.white);
			this.add(textArea);
		}
	}

	private ImageIcon icon;
	private ImageIcon icon1;

	@Override
	protected void paintComponent(Graphics g) {
		if (MyIsif.getStyle().equals("水墨UI")){
			super.paintComponent(g);
			// 更改称谓
//		if (icon == null)
			icon = new ImageIcon("inkImg/newbackground/B232.png");
			g.drawImage(icon.getImage(), 0, 0, 288, 398, this);
		}else {
			super.paintComponent(g);
			// 更改称谓
//		if (icon == null)
			icon = new ImageIcon("skin/8100226/button/hongmu/称谓红木.png");
			g.drawImage(icon.getImage(), 0, 0, 288, 398, this);
		}
	}

	public JLabel getLabnamech() {
		return labnamech;
	}

	public void setLabnamech(JLabel labnamech) {
		this.labnamech = labnamech;
	}

	public JScrollPane getjScrollPane() {
		return jScrollPane;
	}

	public void setjScrollPane(JScrollPane jScrollPane) {
		this.jScrollPane = jScrollPane;
	}

	public JList<String> getListname() {
		return listname;
	}

	public void setListname(JList<String> listname) {
		this.listname = listname;
	}

	public DefaultListModel<String> getModelname() {
		return modelname;
	}

	public void setModelname(DefaultListModel<String> modelname) {
		this.modelname = modelname;
	}

	public RoleOperationPanelBtn getBtnsure() {
		return btnsure;
	}

	public void setBtnsure(RoleOperationPanelBtn btnsure) {
		this.btnsure = btnsure;
	}

	public RoleOperationPanelBtn getBtnhide() {
		return btnhide;
	}

	public void setBtnhide(RoleOperationPanelBtn btnhide) {
		this.btnhide = btnhide;
	}

	public Change_titleJframe getChange_titleJframe() {
		return change_titleJframe;
	}

	public void setChange_titleJframe(Change_titleJframe change_titleJframe) {
		this.change_titleJframe = change_titleJframe;
	}

}
